home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 November / PCWNOV08.iso / Software / Freeware / Adobe Media Player 1.1 / adobe_media_player.air / AMP.swf / scripts / mx / containers / ViewStack.as < prev   
Encoding:
Text File  |  2008-07-17  |  19.1 KB  |  625 lines

  1. package mx.containers
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.DisplayObjectContainer;
  5.    import flash.events.Event;
  6.    import mx.automation.IAutomationObject;
  7.    import mx.core.Container;
  8.    import mx.core.ContainerCreationPolicy;
  9.    import mx.core.EdgeMetrics;
  10.    import mx.core.IInvalidating;
  11.    import mx.core.IUIComponent;
  12.    import mx.core.ScrollPolicy;
  13.    import mx.core.UIComponent;
  14.    import mx.core.mx_internal;
  15.    import mx.effects.Effect;
  16.    import mx.effects.EffectManager;
  17.    import mx.events.ChildExistenceChangedEvent;
  18.    import mx.events.EffectEvent;
  19.    import mx.events.FlexEvent;
  20.    import mx.events.IndexChangedEvent;
  21.    import mx.graphics.RoundedRectangle;
  22.    import mx.managers.HistoryManager;
  23.    import mx.managers.IHistoryManagerClient;
  24.    
  25.    use namespace mx_internal;
  26.    
  27.    public class ViewStack extends Container implements IHistoryManagerClient
  28.    {
  29.       mx_internal static const VERSION:String = "3.0.0.0";
  30.       
  31.       private var dispatchChangeEventPending:Boolean = false;
  32.       
  33.       private var historyManagementEnabledChanged:Boolean = false;
  34.       
  35.       mx_internal var vsPreferredHeight:Number;
  36.       
  37.       private var initialSelectedIndex:int = -1;
  38.       
  39.       private var firstTime:Boolean = true;
  40.       
  41.       mx_internal var _historyManagementEnabled:Boolean = false;
  42.       
  43.       private var overlayChild:Container;
  44.       
  45.       private var overlayTargetArea:RoundedRectangle;
  46.       
  47.       private var proposedSelectedIndex:int = -1;
  48.       
  49.       private var needToInstantiateSelectedChild:Boolean = false;
  50.       
  51.       private var bSaveState:Boolean = false;
  52.       
  53.       mx_internal var vsMinHeight:Number;
  54.       
  55.       private var bInLoadState:Boolean = false;
  56.       
  57.       mx_internal var vsPreferredWidth:Number;
  58.       
  59.       private var _resizeToContent:Boolean = false;
  60.       
  61.       mx_internal var vsMinWidth:Number;
  62.       
  63.       private var lastIndex:int = -1;
  64.       
  65.       private var _selectedIndex:int = -1;
  66.       
  67.       public function ViewStack()
  68.       {
  69.          super();
  70.          addEventListener(ChildExistenceChangedEvent.CHILD_ADD,childAddHandler);
  71.          addEventListener(ChildExistenceChangedEvent.CHILD_REMOVE,childRemoveHandler);
  72.       }
  73.       
  74.       protected function get contentHeight() : Number
  75.       {
  76.          var _loc1_:EdgeMetrics = viewMetricsAndPadding;
  77.          return unscaledHeight - _loc1_.top - _loc1_.bottom;
  78.       }
  79.       
  80.       public function set selectedChild(param1:Container) : void
  81.       {
  82.          var _loc2_:int = getChildIndex(DisplayObject(param1));
  83.          if(_loc2_ >= 0 && _loc2_ < numChildren)
  84.          {
  85.             selectedIndex = _loc2_;
  86.          }
  87.       }
  88.       
  89.       private function systemManager_addedHandler(param1:Event) : void
  90.       {
  91.          if(param1.target is DisplayObjectContainer && DisplayObjectContainer(param1.target).contains(this))
  92.          {
  93.             if(historyManagementEnabled)
  94.             {
  95.                HistoryManager.register(this);
  96.             }
  97.          }
  98.       }
  99.       
  100.       override mx_internal function setActualCreationPolicies(param1:String) : void
  101.       {
  102.          var _loc2_:int = 0;
  103.          var _loc3_:Container = null;
  104.          super.mx_internal::setActualCreationPolicies(param1);
  105.          if(param1 == ContainerCreationPolicy.ALL && numChildren > 0)
  106.          {
  107.             _loc2_ = 0;
  108.             while(_loc2_ < numChildren)
  109.             {
  110.                _loc3_ = getChildAt(_loc2_) as Container;
  111.                if(Boolean(_loc3_) && _loc3_.mx_internal::numChildrenCreated == -1)
  112.                {
  113.                   _loc3_.createComponentsFromDescriptors();
  114.                }
  115.                _loc2_++;
  116.             }
  117.          }
  118.       }
  119.       
  120.       private function dispatchChangeEvent(param1:int, param2:int) : void
  121.       {
  122.          var _loc3_:IndexChangedEvent = new IndexChangedEvent(IndexChangedEvent.CHANGE);
  123.          _loc3_.oldIndex = param1;
  124.          _loc3_.newIndex = param2;
  125.          _loc3_.relatedObject = getChildAt(param2);
  126.          dispatchEvent(_loc3_);
  127.       }
  128.       
  129.       protected function get contentY() : Number
  130.       {
  131.          return getStyle("paddingTop");
  132.       }
  133.       
  134.       protected function commitSelectedIndex(param1:int) : void
  135.       {
  136.          var _loc3_:Container = null;
  137.          var _loc4_:Effect = null;
  138.          if(numChildren == 0)
  139.          {
  140.             _selectedIndex = -1;
  141.             return;
  142.          }
  143.          if(param1 < 0)
  144.          {
  145.             param1 = 0;
  146.          }
  147.          else if(param1 > numChildren - 1)
  148.          {
  149.             param1 = numChildren - 1;
  150.          }
  151.          if(lastIndex != -1 && lastIndex < numChildren)
  152.          {
  153.             Container(getChildAt(lastIndex)).endEffectsStarted();
  154.          }
  155.          if(_selectedIndex != -1)
  156.          {
  157.             selectedChild.endEffectsStarted();
  158.          }
  159.          lastIndex = _selectedIndex;
  160.          if(param1 == lastIndex)
  161.          {
  162.             return;
  163.          }
  164.          _selectedIndex = param1;
  165.          if(initialSelectedIndex == -1)
  166.          {
  167.             initialSelectedIndex = _selectedIndex;
  168.          }
  169.          if(lastIndex != -1 && param1 != -1)
  170.          {
  171.             dispatchChangeEventPending = true;
  172.          }
  173.          var _loc2_:Boolean = false;
  174.          if(lastIndex != -1 && lastIndex < numChildren)
  175.          {
  176.             _loc3_ = Container(getChildAt(lastIndex));
  177.             _loc3_.setVisible(false);
  178.             if(_loc3_.getStyle("hideEffect"))
  179.             {
  180.                _loc4_ = EffectManager.mx_internal::lastEffectCreated;
  181.                if(_loc4_)
  182.                {
  183.                   _loc4_.addEventListener(EffectEvent.EFFECT_END,hideEffectEndHandler);
  184.                   _loc2_ = true;
  185.                }
  186.             }
  187.          }
  188.          if(!_loc2_)
  189.          {
  190.             hideEffectEndHandler(null);
  191.          }
  192.       }
  193.       
  194.       private function instantiateSelectedChild() : void
  195.       {
  196.          if(!selectedChild)
  197.          {
  198.             return;
  199.          }
  200.          if(Boolean(selectedChild) && selectedChild.mx_internal::numChildrenCreated == -1)
  201.          {
  202.             if(initialized)
  203.             {
  204.                selectedChild.addEventListener(FlexEvent.CREATION_COMPLETE,childCreationCompleteHandler);
  205.             }
  206.             selectedChild.createComponentsFromDescriptors(true);
  207.          }
  208.          if(selectedChild is IInvalidating)
  209.          {
  210.             IInvalidating(selectedChild).invalidateSize();
  211.          }
  212.          invalidateSize();
  213.          invalidateDisplayList();
  214.       }
  215.       
  216.       private function initializeHandler(param1:FlexEvent) : void
  217.       {
  218.          overlayChild.removeEventListener(FlexEvent.INITIALIZE,initializeHandler);
  219.          UIComponent(overlayChild).mx_internal::addOverlay(mx_internal::overlayColor,overlayTargetArea);
  220.       }
  221.       
  222.       public function set historyManagementEnabled(param1:Boolean) : void
  223.       {
  224.          if(param1 != mx_internal::_historyManagementEnabled)
  225.          {
  226.             mx_internal::_historyManagementEnabled = param1;
  227.             historyManagementEnabledChanged = true;
  228.             invalidateProperties();
  229.          }
  230.       }
  231.       
  232.       override public function get horizontalScrollPolicy() : String
  233.       {
  234.          return ScrollPolicy.OFF;
  235.       }
  236.       
  237.       private function childAddHandler(param1:ChildExistenceChangedEvent) : void
  238.       {
  239.          var _loc4_:IUIComponent = null;
  240.          var _loc2_:DisplayObject = param1.relatedObject;
  241.          var _loc3_:int = getChildIndex(_loc2_);
  242.          if(_loc2_ is IUIComponent)
  243.          {
  244.             _loc4_ = IUIComponent(_loc2_);
  245.             _loc4_.visible = false;
  246.          }
  247.          if(numChildren == 1 && proposedSelectedIndex == -1)
  248.          {
  249.             proposedSelectedIndex = 0;
  250.             invalidateProperties();
  251.          }
  252.          else if(_loc3_ <= _selectedIndex && numChildren > 1)
  253.          {
  254.             ++selectedIndex;
  255.          }
  256.          if(!(_loc2_ as IAutomationObject))
  257.          {
  258.          }
  259.          IAutomationObject(_loc2_).showInAutomationHierarchy = true;
  260.       }
  261.       
  262.       public function get resizeToContent() : Boolean
  263.       {
  264.          return _resizeToContent;
  265.       }
  266.       
  267.       private function systemManager_removedHandler(param1:Event) : void
  268.       {
  269.          if(param1.target is DisplayObjectContainer && DisplayObjectContainer(param1.target).contains(this))
  270.          {
  271.             HistoryManager.unregister(this);
  272.          }
  273.       }
  274.       
  275.       public function saveState() : Object
  276.       {
  277.          var _loc1_:int = _selectedIndex == -1 ? 0 : _selectedIndex;
  278.          return {"selectedIndex":_loc1_};
  279.       }
  280.       
  281.       override public function get autoLayout() : Boolean
  282.       {
  283.          return true;
  284.       }
  285.       
  286.       override mx_internal function removeOverlay() : void
  287.       {
  288.          if(overlayChild)
  289.          {
  290.             UIComponent(overlayChild).mx_internal::removeOverlay();
  291.             overlayChild = null;
  292.          }
  293.       }
  294.       
  295.       private function childCreationCompleteHandler(param1:FlexEvent) : void
  296.       {
  297.          param1.target.removeEventListener(FlexEvent.CREATION_COMPLETE,childCreationCompleteHandler);
  298.          param1.target.dispatchEvent(new FlexEvent(FlexEvent.SHOW));
  299.       }
  300.       
  301.       [Bindable("valueCommit")]
  302.       public function get selectedChild() : Container
  303.       {
  304.          if(selectedIndex == -1)
  305.          {
  306.             return null;
  307.          }
  308.          return Container(getChildAt(selectedIndex));
  309.       }
  310.       
  311.       private function hideEffectEndHandler(param1:EffectEvent) : void
  312.       {
  313.          if(param1)
  314.          {
  315.             param1.currentTarget.removeEventListener(EffectEvent.EFFECT_END,hideEffectEndHandler);
  316.          }
  317.          needToInstantiateSelectedChild = true;
  318.          invalidateProperties();
  319.          if(bSaveState)
  320.          {
  321.             HistoryManager.save();
  322.             bSaveState = false;
  323.          }
  324.       }
  325.       
  326.       override public function set horizontalScrollPolicy(param1:String) : void
  327.       {
  328.       }
  329.       
  330.       public function get historyManagementEnabled() : Boolean
  331.       {
  332.          return mx_internal::_historyManagementEnabled;
  333.       }
  334.       
  335.       public function loadState(param1:Object) : void
  336.       {
  337.          var _loc2_:int = !!param1 ? int(param1.selectedIndex) : 0;
  338.          if(_loc2_ == -1)
  339.          {
  340.             _loc2_ = initialSelectedIndex;
  341.          }
  342.          if(_loc2_ == -1)
  343.          {
  344.             _loc2_ = 0;
  345.          }
  346.          if(_loc2_ != _selectedIndex)
  347.          {
  348.             bInLoadState = true;
  349.             selectedIndex = _loc2_;
  350.             bInLoadState = false;
  351.          }
  352.       }
  353.       
  354.       protected function get contentWidth() : Number
  355.       {
  356.          var _loc1_:EdgeMetrics = viewMetricsAndPadding;
  357.          return unscaledWidth - _loc1_.left - _loc1_.right;
  358.       }
  359.       
  360.       override protected function commitProperties() : void
  361.       {
  362.          super.commitProperties();
  363.          if(historyManagementEnabledChanged)
  364.          {
  365.             if(historyManagementEnabled)
  366.             {
  367.                HistoryManager.register(this);
  368.             }
  369.             else
  370.             {
  371.                HistoryManager.unregister(this);
  372.             }
  373.             historyManagementEnabledChanged = false;
  374.          }
  375.          if(proposedSelectedIndex != -1)
  376.          {
  377.             commitSelectedIndex(proposedSelectedIndex);
  378.             proposedSelectedIndex = -1;
  379.          }
  380.          if(needToInstantiateSelectedChild)
  381.          {
  382.             instantiateSelectedChild();
  383.             needToInstantiateSelectedChild = false;
  384.          }
  385.          if(dispatchChangeEventPending)
  386.          {
  387.             dispatchChangeEvent(lastIndex,selectedIndex);
  388.             dispatchChangeEventPending = false;
  389.          }
  390.          if(firstTime)
  391.          {
  392.             firstTime = false;
  393.             systemManager.addEventListener(Event.ADDED,systemManager_addedHandler,false,0,true);
  394.             systemManager.addEventListener(Event.REMOVED,systemManager_removedHandler,false,0,true);
  395.          }
  396.       }
  397.       
  398.       public function set resizeToContent(param1:Boolean) : void
  399.       {
  400.          if(param1 != _resizeToContent)
  401.          {
  402.             _resizeToContent = param1;
  403.             if(param1)
  404.             {
  405.                invalidateSize();
  406.             }
  407.          }
  408.       }
  409.       
  410.       override public function createComponentsFromDescriptors(param1:Boolean = true) : void
  411.       {
  412.          if(actualCreationPolicy == ContainerCreationPolicy.ALL)
  413.          {
  414.             super.createComponentsFromDescriptors();
  415.             return;
  416.          }
  417.          var _loc2_:int = numChildren;
  418.          var _loc3_:int = !!childDescriptors ? int(childDescriptors.length) : 0;
  419.          var _loc4_:int = 0;
  420.          while(_loc4_ < _loc3_)
  421.          {
  422.             createComponentFromDescriptor(childDescriptors[_loc4_],false);
  423.             _loc4_++;
  424.          }
  425.          mx_internal::numChildrenCreated = numChildren - _loc2_;
  426.          processedDescriptors = true;
  427.       }
  428.       
  429.       override protected function measure() : void
  430.       {
  431.          var _loc1_:Number = NaN;
  432.          var _loc2_:Number = NaN;
  433.          var _loc3_:Number = NaN;
  434.          var _loc4_:Number = NaN;
  435.          var _loc8_:Container = null;
  436.          super.measure();
  437.          _loc1_ = 0;
  438.          _loc2_ = 0;
  439.          _loc3_ = 0;
  440.          _loc4_ = 0;
  441.          if(Boolean(mx_internal::vsPreferredWidth) && !_resizeToContent)
  442.          {
  443.             measuredMinWidth = mx_internal::vsMinWidth;
  444.             measuredMinHeight = mx_internal::vsMinHeight;
  445.             measuredWidth = mx_internal::vsPreferredWidth;
  446.             measuredHeight = mx_internal::vsPreferredHeight;
  447.             return;
  448.          }
  449.          if(numChildren > 0 && selectedIndex != -1)
  450.          {
  451.             _loc8_ = Container(getChildAt(selectedIndex));
  452.             _loc1_ = _loc8_.minWidth;
  453.             _loc3_ = _loc8_.getExplicitOrMeasuredWidth();
  454.             _loc2_ = _loc8_.minHeight;
  455.             _loc4_ = _loc8_.getExplicitOrMeasuredHeight();
  456.          }
  457.          var _loc5_:EdgeMetrics = viewMetricsAndPadding;
  458.          var _loc6_:Number = _loc5_.left + _loc5_.right;
  459.          _loc1_ += _loc6_;
  460.          _loc3_ += _loc6_;
  461.          var _loc7_:Number = _loc5_.top + _loc5_.bottom;
  462.          _loc2_ += _loc7_;
  463.          _loc4_ += _loc7_;
  464.          measuredMinWidth = _loc1_;
  465.          measuredMinHeight = _loc2_;
  466.          measuredWidth = _loc3_;
  467.          measuredHeight = _loc4_;
  468.          if(Boolean(selectedChild) && Container(selectedChild).mx_internal::numChildrenCreated == -1)
  469.          {
  470.             return;
  471.          }
  472.          if(numChildren == 0)
  473.          {
  474.             return;
  475.          }
  476.          mx_internal::vsMinWidth = _loc1_;
  477.          mx_internal::vsMinHeight = _loc2_;
  478.          mx_internal::vsPreferredWidth = _loc3_;
  479.          mx_internal::vsPreferredHeight = _loc4_;
  480.       }
  481.       
  482.       override public function set verticalScrollPolicy(param1:String) : void
  483.       {
  484.       }
  485.       
  486.       public function set selectedIndex(param1:int) : void
  487.       {
  488.          if(param1 == selectedIndex)
  489.          {
  490.             return;
  491.          }
  492.          proposedSelectedIndex = param1;
  493.          invalidateProperties();
  494.          if(historyManagementEnabled && _selectedIndex != -1 && !bInLoadState)
  495.          {
  496.             bSaveState = true;
  497.          }
  498.          dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
  499.       }
  500.       
  501.       override mx_internal function addOverlay(param1:uint, param2:RoundedRectangle = null) : void
  502.       {
  503.          if(overlayChild)
  504.          {
  505.             mx_internal::removeOverlay();
  506.          }
  507.          overlayChild = selectedChild;
  508.          if(!overlayChild)
  509.          {
  510.             return;
  511.          }
  512.          mx_internal::overlayColor = param1;
  513.          overlayTargetArea = param2;
  514.          if(Boolean(selectedChild) && selectedChild.mx_internal::numChildrenCreated == -1)
  515.          {
  516.             selectedChild.addEventListener(FlexEvent.INITIALIZE,initializeHandler);
  517.          }
  518.          else
  519.          {
  520.             initializeHandler(null);
  521.          }
  522.       }
  523.       
  524.       override public function set autoLayout(param1:Boolean) : void
  525.       {
  526.       }
  527.       
  528.       override public function get verticalScrollPolicy() : String
  529.       {
  530.          return ScrollPolicy.OFF;
  531.       }
  532.       
  533.       [Bindable("valueCommit")]
  534.       [Bindable("change")]
  535.       public function get selectedIndex() : int
  536.       {
  537.          return proposedSelectedIndex == -1 ? _selectedIndex : proposedSelectedIndex;
  538.       }
  539.       
  540.       private function childRemoveHandler(param1:ChildExistenceChangedEvent) : void
  541.       {
  542.          var _loc2_:DisplayObject = param1.relatedObject;
  543.          var _loc3_:int = getChildIndex(_loc2_);
  544.          if(_loc3_ > selectedIndex)
  545.          {
  546.             return;
  547.          }
  548.          var _loc4_:int = selectedIndex;
  549.          if(_loc3_ < _loc4_ || _loc4_ == numChildren - 1)
  550.          {
  551.             if(_loc4_ == 0)
  552.             {
  553.                selectedIndex = -1;
  554.                _selectedIndex = -1;
  555.             }
  556.             else
  557.             {
  558.                --selectedIndex;
  559.             }
  560.          }
  561.          else if(_loc3_ == _loc4_)
  562.          {
  563.             needToInstantiateSelectedChild = true;
  564.             invalidateProperties();
  565.          }
  566.       }
  567.       
  568.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  569.       {
  570.          var _loc8_:Container = null;
  571.          var _loc9_:Number = NaN;
  572.          var _loc10_:Number = NaN;
  573.          super.updateDisplayList(param1,param2);
  574.          var _loc3_:int = numChildren;
  575.          var _loc4_:Number = contentWidth;
  576.          var _loc5_:Number = contentHeight;
  577.          var _loc6_:Number = contentX;
  578.          var _loc7_:Number = contentY;
  579.          if(selectedIndex != -1)
  580.          {
  581.             _loc8_ = Container(getChildAt(selectedIndex));
  582.             _loc9_ = _loc4_;
  583.             _loc10_ = _loc5_;
  584.             if(!isNaN(_loc8_.percentWidth))
  585.             {
  586.                if(_loc9_ > _loc8_.maxWidth)
  587.                {
  588.                   _loc9_ = _loc8_.maxWidth;
  589.                }
  590.             }
  591.             else if(_loc9_ > _loc8_.explicitWidth)
  592.             {
  593.                _loc9_ = _loc8_.explicitWidth;
  594.             }
  595.             if(!isNaN(_loc8_.percentHeight))
  596.             {
  597.                if(_loc10_ > _loc8_.maxHeight)
  598.                {
  599.                   _loc10_ = _loc8_.maxHeight;
  600.                }
  601.             }
  602.             else if(_loc10_ > _loc8_.explicitHeight)
  603.             {
  604.                _loc10_ = _loc8_.explicitHeight;
  605.             }
  606.             if(_loc8_.width != _loc9_ || _loc8_.height != _loc10_)
  607.             {
  608.                _loc8_.setActualSize(_loc9_,_loc10_);
  609.             }
  610.             if(_loc8_.x != _loc6_ || _loc8_.y != _loc7_)
  611.             {
  612.                _loc8_.move(_loc6_,_loc7_);
  613.             }
  614.             _loc8_.visible = true;
  615.          }
  616.       }
  617.       
  618.       protected function get contentX() : Number
  619.       {
  620.          return getStyle("paddingLeft");
  621.       }
  622.    }
  623. }
  624.  
  625.